package com.dnb.webmash.playmaker.client.mediaplayer;

import com.dnb.webmash.playmaker.shared.PlayerConfig;
import com.dnb.webmash.playmaker.shared.PlayerType;
import com.dnb.webmash.playmaker.shared.PlaylistItem;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;

public abstract class MediaPlayer extends Widget{//TODO CHANGE TO A FILL IN THE BLANKS PLAYER THAT GRABS THE VALUES FROM THE PLAYERDEFS... REMOVE ABSTRACT, CREATE PLAYERTYPES TO STOP EXTENDING THIS
	protected Element myElement;
	protected PlaylistItem mediaIt;
	protected PlayerType myType;
	private String width, height;
	
	public PlayerType getType() {
		return myType;
	}
	public void embedItem(PlaylistItem mediaItem) {
		if (mediaItem!=null){
			this.mediaIt = mediaItem;
			if (this.mediaIt.getPlayerType().equals(this.myType)){
				appendMediaParameter();				
				embed();
				setMyElemDefaults();//TODO FIX THIS DOES NOT WORK ON EMBEDplayer
			}
			//TODO else ?
		}
	}	
	protected abstract void embed();
	
	public void setWidth(String width) {
		this.width = width;
		super.setWidth(width);		
	}
	public void setHeight(String height) {
		this.height = height;
		super.setHeight(height);			
	}
	
	protected void setMyElemDefaults() {//TODO USE THIS FOR MORE DEFAULTS
		myElement.setAttribute("width", this.width);
		myElement.setAttribute("height", this.height);
	}
	
	protected void appendMediaParameter() {
		Element paramElement = Document.get().createElement("param");
		paramElement.setAttribute("name", "media");
		paramElement.setAttribute("value", mediaIt.getFullURL());
		getElement().appendChild(paramElement);
	}
	public void applySettings(PlayerConfig playerprefs) {
		// TODO CHECK IF PREFS ARE OF SAME TYPE AS THIS, THEN APPLY THE OPTION LIST
		
	}
}
